﻿using System;
using System.Data;
using System.Drawing;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using HiauPdm.Bll;
using HiauPdm.Web;

namespace HiauPdm.Web
{
    public partial class CpSjCxLs : PageBase
    {
        protected override bool IsAccess()
        {
            return IsAccess("CpSjCx.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                TreeCpSj.Nodes.Add(new TreeNode("产品设计浏览&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:self.location.replace(self.location);' style='font-weight:normal;' title='刷新'>[刷新]</a>&nbsp;<a href='javascript:CloseTree();' style='font-weight:normal;' title='返回到左菜单'>[返回到左菜单]</a>", string.Empty));
                TreeCpSj.Nodes[0].SelectAction = TreeNodeSelectAction.None;
                BindData(TreeCpSj.Nodes[0]);
                TreeCpSj.ExpandDepth = 1;
            }
        }

        private void BindData(TreeNode tRoot)
        {
            string sCpSjLb = string.Empty;
            if (Request.QueryString["CpSjLb"] != null)
            {
                sCpSjLb = Request.QueryString["CpSjLb"].Trim();
            }
            int iCpSjZt = -1;
            if ((Request.QueryString["CpSjZt"] != null) && BGlobal.IsNumeric(Request.QueryString["CpSjZt"].Trim()))
            {
                iCpSjZt = Convert.ToInt32(Request.QueryString["CpSjZt"].Trim());
            }
            string sCpSjDjr = string.Empty;
            if (Request.QueryString["CpSjDjr"] != null)
            {
                sCpSjDjr = Request.QueryString["CpSjDjr"].Trim();
            }
            string sCpSjWhere = string.Empty;
            if (Request.QueryString["CpSjWhere"] != null)
            {
                sCpSjWhere = Request.QueryString["CpSjWhere"].Trim();
            }
            int iCpSjIdYy = -1;
            if (sCpSjWhere.IndexOf("FindReferences|") == 0 && BGlobal.IsNumeric(sCpSjWhere.Substring(15))) // 查找引用
            {
                iCpSjIdYy = Convert.ToInt32(sCpSjWhere.Substring(15));
                sCpSjWhere = string.Empty;
            }
            int iWgjIdYy = -1;
            if (sCpSjWhere.IndexOf("FindWgjReferences|") == 0 && BGlobal.IsNumeric(sCpSjWhere.Substring(18))) // 查找引用
            {
                iWgjIdYy = Convert.ToInt32(sCpSjWhere.Substring(18));
                sCpSjWhere = string.Empty;
            }
            DataSet dsCpSj = null;
            if (sCpSjLb != string.Empty || iCpSjZt != -1 || sCpSjDjr != string.Empty || sCpSjWhere != string.Empty || iCpSjIdYy != -1 || iWgjIdYy != -1)
            {
                dsCpSj = BCpSjCx.GetCpSjCxTree(sCpSjLb, iCpSjZt, sCpSjDjr, sCpSjWhere, iCpSjIdYy, iWgjIdYy);
            }
            if (dsCpSj != null && dsCpSj.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dsCpSj.Tables[0].Rows)
                {
                    TreeNode tn = new TreeNode(string.Format("[{0}]{1}{2}", dr["代号"], dr["名称"], dr["规格型号"]), dr["ID"].ToString());
                    tn.ToolTip = tn.Text;
                    tn.PopulateOnDemand = ((bool)dr["含零部件"] | (bool)dr["含外购件"]);
                    tn.NavigateUrl = "javascript:CpSjBrowse('" + dr["ID"].ToString() + "');";
                    tRoot.ChildNodes.Add(tn);
                }
            }
            else
            {
                tRoot.ChildNodes.Add(new TreeNode("<span style='color:Black;'>[未找到产品设计记录]</span>", string.Empty));
                tRoot.ChildNodes[0].SelectAction = TreeNodeSelectAction.None;
            }
        }

        protected void TreeCpSj_TreeNodePopulate(object sender, TreeNodeEventArgs e)
        {
            DataSet dsCpSj = BCpSjCx.GetCpSjCxTree(int.Parse(e.Node.Value));
            if (dsCpSj != null && dsCpSj.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dsCpSj.Tables[0].Rows)
                {
                    TreeNode tn = new TreeNode(string.Format("[{0}]{1}{2}", dr["代号"], dr["名称"], dr["规格型号"]), dr["ID"].ToString());
                    tn.ToolTip = tn.Text;
                    tn.PopulateOnDemand = ((bool)dr["含零部件"] | (bool)dr["含外购件"]);
                    tn.NavigateUrl = "javascript:CpSjBrowse('" + dr["ID"].ToString() + "');";
                    e.Node.ChildNodes.Add(tn);
                }
            }
            DataSet dsWgj = BWgjCx.GetWgjCxTree(int.Parse(e.Node.Value));
            if (dsWgj != null && dsWgj.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in dsWgj.Tables[0].Rows)
                {
                    TreeNode tn = new TreeNode(string.Format("[{0}]{1}{2}", dr["代号"], dr["名称"], dr["规格型号"]), dr["ID"].ToString());
                    tn.ToolTip = tn.Text;
                    tn.PopulateOnDemand = false;
                    tn.NavigateUrl = "javascript:WgjBrowse('" + dr["ID"].ToString() + "');";
                    e.Node.ChildNodes.Add(tn);
                }
            }
        }
    }
}